﻿using System;
using System.Data;
using Spring.Data.Common;
using TeamTasker.Contracts;
using TeamTasker.Utils;

namespace TeamTasker.Server.DataAccess
{
    public class SessionDAO : BaseDAO<Session>
    {
        public override Session Load(long id)
        {
            throw new System.NotImplementedException();
        }

        public override void Save(Session entity)
        {
            Validate.NotNull(entity, "Session entity is illegal: null");
            if (entity.ID == 0)
            {
                IDbParameters param = AdoTemplate.CreateDbParameters();
                param.Add("ID", SqlDbType.BigInt).Value = entity.ID = SeqGen.GetNextID();
                param.Add("UserID", SqlDbType.BigInt).Value = entity.UserID;
                param.Add("StartTime", SqlDbType.DateTime).Value = entity.StartTime;
                param.Add("LastRequestTime", SqlDbType.DateTime).Value = entity.LastRequestTime;
                AdoTemplate.ExecuteNonQuery(CommandType.Text,
                    @"insert into Session(ID, UserID, StartTime, LastRequestTime) 
                        values(@ID, @UserID, @StartTime, @LastRequestTime)", param);
            }
            else
            {
                throw new NotImplementedException("Session update is not implemented");
            }            
        }

        public override void Delete(long id)
        {
            throw new System.NotImplementedException();
        }
    }
}
